<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* select,
        option {
            border: 1px solid red;
            line-height: 50px;
            height: 50px;
        } */

        /* span {
            width: 20px;
            height: 20px;
            display: block;
            border: 1px solid #000;
        }

        .on {
            border-color: red;
            background-color: red;
            background-image: url();
        } */

        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .select {
            width: 200px;
            border: 1px solid #000;
            text-align: center;
            margin: 50px;
        }

        .select span {
            display: block;
            cursor: pointer;
        }

        ul {
            display: none;
        }

        ul li {
            border-top: 1px solid #000;
        }
    </style>
</head>

<body>

    <!-- <span></span> -->

    <!-- <select name="" id="">
        <option value="">111</option>
        <option value="">111</option>
        <option value="">111</option>

    </select> -->


    <div class="select">
        <span>请选择</span>
        <ul>
            <li>湖北</li>
            <li>湖南</li>
            <li>河南</li>
        </ul>
    </div>

    <script>

        // span的事件和li的事件都会触发 document的事件  ---事件冒泡了




        var oSpan = document.querySelector('span');
        var oUl = document.querySelector('ul');

        oSpan.onclick = function (e) {
            e.stopPropagation();

            // ul显示
            oUl.style.display = 'block';
        }


        // 获取所有的li
        var oLis = document.querySelectorAll('li');
        for (var i = 0; i < oLis.length; i++) {
            oLis[i].onclick = function () {
                oSpan.innerHTML = this.innerHTML;
                // 利用了事件冒泡 --- li的事件会触发document的事件 --- ul就能可以隐藏 了
                // oUl.style.display = 'none';
            }
        }


        document.onclick = function () {
            oUl.style.display = 'none';
        }

    </script>

</body>

</html>